import { usePeFile } from "./hooks/pe.ts";

/**
 * @author tongxin
 * @date 2024/4/22 11:03
 */
export class StringTable {
  STRING_TABLE_MAGIC = "040904B0" as const;
  LENGTH = 22 as const;
  length: number;
  valueLength: number;
  type: number;
  signature: string;
  offset: number;
  padding: number;

  constructor(byteArray: IByteArray, offset: number) {
    const {calculatePadding} = usePeFile();
    this.offset = offset;

    this.length = byteArray.readWord();
    this.valueLength = byteArray.readWord();
    this.type = byteArray.readWord();
    this.signature = byteArray.readString(this.STRING_TABLE_MAGIC.length * 2);
    this.padding = calculatePadding(this.offset + byteArray.getOffset());
  }

  getEndOffset() {
    return this.offset + this.LENGTH + this.valueLength + this.padding;
  }
}
